package com.ymatou.iapi.trading.userquery.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.CollectionUtils;

import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.BargainGroupService;
import com.ymatou.iapi.synctrade.parameter.mongo.Order;
import com.ymatou.iapi.synctrade.parameter.mongo.UserIndex;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymatou.iapi.trading.userquery.parameter.resp.GetBuyerOrderInfosResp;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;

import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.common.enums.OrderStatusEnum;
import com.ymttest.common.order.userquery.OrderInfoBuilder;
import com.ymttest.common.order.userquery.model.vo.BargainGroupInfo;
import com.ymttest.common.order.userquery.model.vo.OrderInfo;
import com.ymttest.database.mongo.OrderQueryWapper;
import com.ymttest.database.mongo.UserIndexQueryWapper;
import com.ymttest.database.mongo.config.MongoOrderConfig;
import com.ymttest.database.mongo.config.OrderField;
import com.ymttest.database.mongo.config.SchemaField;
import com.ymttest.database.mongo.config.UserIndexField;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

/**
 * 获取买家订单列表
 */
@TestSuite
public class Ts_GetBuyerOrderInfosV2 {

	private static com.ymatou.iapi.trading.userquery.parameter.GetBuyerOrderInfosBean req;
	private static com.ymatou.iapi.trading.userquery.service.GetBuyerOrderInfosV2Call call;
	
	private static Integer userId = 20238699;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买家订单列表");
	}

	@Before
	public void caseUp() {
		req = new com.ymatou.iapi.trading.userquery.parameter.GetBuyerOrderInfosBean();
		call = new com.ymatou.iapi.trading.userquery.service.GetBuyerOrderInfosV2Call();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private List<Order> getBuyerOrders(List<Criteria> criteriaList) {

		List<Order> orders = new ArrayList<Order>();

		long queryLastMainOrderId = req.getLastOrderId();

		try {

			MongoTemplate template = new MongoOrderConfig().mongoTemplate();

			// add 03-28 传入订单列表，忽略其它参数
			if (DataUtil.isNullOrEmpty(req.getOrderIdList())) {

				if (req.getLastOrderId() > 0
						&& req.isLastOrderIdIsRealOrderId()) {

					Query query = new Query();

					query.fields().include(UserIndexField.MAIN_ORDER_ID);

					UserIndex userIndex = new UserIndexQueryWapper()
							.findByIdWithQuery(query, req.getLastOrderId(),
									req.getBuyerId());

					if (userIndex != null) {
						queryLastMainOrderId = userIndex.getMainOrderId();
					}
				}

				if (queryLastMainOrderId > 0) {

					criteriaList.add(Criteria.where(
							UserIndexField.MAIN_ORDER_ID).lt(
							queryLastMainOrderId));
				}

				criteriaList.add(Criteria.where(OrderField.USER_ID).is(
						req.getBuyerId()).norOperator(
								Criteria.where(UserIndexField.HUNTER_ID)
								.gt(0)));
				criteriaList.add(Criteria.where(OrderField.DELETED).is(false));

				if (!DataUtil.isNullOrEmpty(req.getOrderStatusList())) {
					criteriaList.add(Criteria.where(OrderField.TRADING_STATUS)
							.in(req.getOrderStatusList()));
				}

				if (!StringUtils.isBlank(req.getProductId())
						|| !StringUtils.isBlank(req.getTitle())) {
					Criteria products = Criteria.where(OrderField.PRODUCTS);
					Criteria elemMatch = null;
					if (!StringUtils.isBlank(req.getProductId())) {
						elemMatch = Criteria.where("prdId").is(
								req.getProductId());
					}
					if (!StringUtils.isBlank(req.getTitle())) {
						Criteria title = Criteria.where("title").regex(
								req.getTitle());
						if (elemMatch == null) {
							elemMatch = title;
						} else {
							elemMatch.andOperator(title);
						}
					}
					products.elemMatch(elemMatch);
					criteriaList.add(products);
				}
				if (req.getLastOrderId() > 0
						&& req.isLastOrderIdIsRealOrderId()) {
					criteriaList.add(Criteria.where(OrderField.MAIN_ORDER_ID)
							.lt(req.getLastOrderId()));
				}

				Query query = new Query(new Criteria().andOperator(criteriaList
						.toArray(new Criteria[0])));

				query.with(new Sort(Sort.Direction.DESC,
						OrderField.ADD_TIME));

				query.limit(200);

				orders = template.find(query, Order.class, SchemaField.ORDER);

			} else {

				Query query = Query.query(Criteria.where("_id").in(
						req.getOrderIdList()));

				orders = template.find(query, Order.class, SchemaField.ORDER);

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return orders;
	}

	public void constructExpectedResult(GetBuyerOrderInfosResp resp) {

		List<Criteria> criteriaList = new ArrayList<Criteria>();

		// 处理所有数据，内存分页，找出分页条数的主单号和订单号
		Long lastMainOrderId = null;
		List<Long> orderIds = new ArrayList<Long>();

		if (CollectionUtils.isEmpty(req.getOrderIdList())) {

			// 商品ID不为空，或商品title不为空 程序走ES查询(用例改为查mongo)
			List<Order> orderList = getBuyerOrders(criteriaList);
			if (!CollectionUtils.isEmpty(orderList)) {
				Set<Long> mainOrderIdSet = new HashSet<Long>();
				int length = orderList.size();
				for (int i = 0; i < length; i++) {
					long mainOrderId = orderList.get(i).getMainOrderId();

					if (mainOrderIdSet.size() != req.getOrderNum()) {
						mainOrderIdSet.add(mainOrderId);
						lastMainOrderId = mainOrderId;
					}
					// 如查当前mainorderId 小于最后一个mainorderId 则退出
					if (lastMainOrderId != null
							&& mainOrderId < lastMainOrderId) {
						break;
					}
					orderIds.add(orderList.get(i).getId());
				}
			}

		} else {

			// 当订单列表不为空时,除buyerId之外的查询条件忽略
			Query query = Query
					.query(Criteria
							.where("_id")
							.in(req.getOrderIdList())
							.norOperator(
									Criteria.where(UserIndexField.HUNTER_ID)
											.gt(0)));
			List<UserIndex> userIndexList = new UserIndexQueryWapper().find(
					query, req.getBuyerId(), UserIndex.class);
			orderIds.addAll(userIndexList.stream().map(UserIndex::getId)
					.collect(Collectors.toList()));

		}

		List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
		if (!CollectionUtils.isEmpty(orderIds)) {
			
			List<Order> orders = new OrderQueryWapper().findByIds(orderIds);
			
			// 按主单号降序排序
			Collections.sort(orders,
					(o1, o2) -> o2.getAddTime().compareTo(o1.getAddTime()));
			orders.forEach(o -> orderInfoList.add(OrderInfoBuilder
					.convertFromOrder(o, false)));
		}

		if (!DataUtil.isNullOrEmpty(req.getOrderIdList())) {
			lastMainOrderId = null;
		}

		resp.setOrderInfos(orderInfoList);
		resp.setLastOrderId(lastMainOrderId);

	}

	private void verify() {

		GetBuyerOrderInfosResp expectResponse = new GetBuyerOrderInfosResp();
		constructExpectedResult(expectResponse);
		GetBuyerOrderInfosResp actualResponse = call
				.getBuyerOrderInfosResponseV2();
		DataUtil.verify(expectResponse.getLastOrderId(),
				actualResponse.getLastOrderId(), "验证LastOrderId");

		List<OrderInfo> expectOrders = expectResponse.getOrderInfos();
		List<OrderInfo> actualOrders = actualResponse.getOrderInfos();

		if (expectOrders == null) {
			DataUtil.verify(null, actualOrders, "验证OrderInfos == null");
		}

		for (int i = 0; i < expectOrders.size(); i++) {
			OrderInfo expect = expectOrders.get(i);
			OrderInfo actual = actualOrders.get(i);
			expect.verify(actual);
			BargainGroupInfo expBargainGroupInfo = getBargainGroupInfoFromMssql(expect
					.getOrderId());
			BargainGroupInfo actBargainGroupInfo = actual.getBargainGroup();
			Logger.comment("验证砍价团信息, 比对sqlserver数据");

			if (expBargainGroupInfo == null) {
				DataUtil.verify(
						null,
						actBargainGroupInfo,
						String.format(
								"验证 sqlserver中订单id:%d 没有参加砍价团(orderInfos.bargainGroup == null)",
								expect.getOrderId()));
			} else {
				DataUtil.verifyObject(expBargainGroupInfo, actBargainGroupInfo,
						"砍价团信息orderInfos.bargainGroup");
			}
		}
	}

	public BargainGroupInfo getBargainGroupInfoFromMssql(long orderId) {

		Order order = new OrderQueryWapper().findById(orderId);
		BargainGroupInfo info = null;

		if (null == order.getBizId()) {
			return info;
		} else {

			info = new BargainGroupInfo();
			info.setBizId(order.getBizId());
			info.setBizStatus(order.getBizStatus());
			info.setBizSubType(order.getBizSubType());
		}

		return info;
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_001() {
		Logger.start(true, "订单状态为1 获取买家订单列表, 参数全传(根据orderid查)，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			req.setBuyerId(userId);
			req.setOrderNum(2);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_002() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 只传必填字段BuyuerId,OrderNum，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_003() {
		Logger.start(true, "获取买家订单列表, OrderNum为必填");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setLastOrderId(112443995);
			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatusList.add(OrderStatusEnum.ApplyForPostPay.getValue());
			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatusList.add(OrderStatusEnum.SystemCancel.getValue());
			orderStatusList.add(OrderStatusEnum.Shipped.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAcceptCancel.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAccept.getValue());
			req.setOrderStatusList(orderStatusList);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			Logger.verifyEquals("400", call.getCode(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_004() {
		Logger.start(true, "获取买家订单列表, BuyerId为必填");
		try {
			req.setOrderNum(10);
			req.setLastOrderId(0);
			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatusList.add(OrderStatusEnum.ApplyForPostPay.getValue());
			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatusList.add(OrderStatusEnum.SystemCancel.getValue());
			orderStatusList.add(OrderStatusEnum.Shipped.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAcceptCancel.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAccept.getValue());
			req.setOrderStatusList(orderStatusList);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			Logger.verifyEquals("400", call.getCode(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_006() {
		Logger.start(true, "获取买家订单列表, 必填字段+LastOrderIdIsRealOrderId,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			call.setData(req);
			call.callService();

			req.setLastOrderId(call.getBuyerOrderInfosResponseV2()
					.getLastOrderId());

			call.setData(req);
			call.callService();

			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_007() {
		Logger.start(true, "获取买家订单列表, 必填字段+orderStatusList,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			List<Integer> orderStatusList = new ArrayList<Integer>();
			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatusList.add(OrderStatusEnum.ApplyForPostPay.getValue());
			// orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatusList.add(OrderStatusEnum.SystemCancel.getValue());
			orderStatusList.add(OrderStatusEnum.Shipped.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAcceptCancel.getValue());
			orderStatusList.add(OrderStatusEnum.SellerAccept.getValue());
			req.setOrderStatusList(orderStatusList);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_008() {
		Logger.start(true, "获取买家订单列表, 必填字段+RefundedOrderOnly,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_009() {
		Logger.start(true, "获取买家订单列表, 必填字段+ToBeEvaluatedDays,查询成功");
		try {
			int UserId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			req.setBuyerId(UserId);
			req.setOrderNum(10);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_010() {
		Logger.start(true, "删除的订单不在列表范围内");
		try {
			Logger.comment("准备一个删除的订单");
			TradingServiceResp placeOrder = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long userId = placeOrder.getUserId();

			new OrderCallService().salesMarkOrderDeleted(orderId, userId, true);
			TradingSyncService.getSyncResult(orderId);
			Logger.comment("订单准备完成");

			req.setBuyerId((int)userId);
			req.setOrderNum(10);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	/**
	 * 恢复删除的功能目前没有需求，不需要测试
	 */
	public void Tc_GetBuyerOrderInfosV2_011() {
		Logger.start(true, "恢复删除的订单需要返回给用户");
		try {
			Logger.comment("准备一个恢复删除的订单");
			TradingServiceResp placeOrder = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrder.getOrderList().get(0).getOrderId();
			long userId = placeOrder.getUserId();
			new OrderCallService().salesMarkOrderDeleted(orderId, userId, true);
			TradingSyncService.getSyncResult(orderId);
			
			new OrderCallService().salesMarkOrderDeleted(orderId, userId, false);
			TradingSyncService.getSyncResult(orderId);
			Logger.comment("订单准备完成");

			req.setBuyerId((int)userId);
			req.setOrderNum(10);
			req.setToBeEvaluatedDays(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_012() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品title 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(2);
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			req.setTitle("智力车厘子");
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_013() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品productid 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(2);
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			req.setProductId("11f2fc36-75f2-48c5-b35b-ba789f8351cc");
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_014() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品productid 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(OrderStatusEnum.AccountPaid.getValue());
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			req.setTitle("智力车厘子");
			call.setData(req);
			call.callService();

			req.setLastOrderId(call.getBuyerOrderInfosResponseV2()
					.getLastOrderId());
			req.setLastOrderIdIsRealOrderId(true);

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_015() {
		Logger.start(true, "订单状态为2 获取买家订单列表, 传入商品productid 关键字，查询成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(2);
			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setLastOrderId(0);
			req.setOrderStatusList(orderStatusList);
			req.setProductId("11f2fc36-75f2-48c5-b35b-ba789f8351cc");
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_016() {
		Logger.start(true, "验证砍价团信息，查询成功, 团长开团 组团失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 砍价团id
			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);

			// 参团
			TradingServiceResp placeOrder2 = BargainGroupService
					.joinGroup(bizId);

			long orderId = placeOrder2.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, -3);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(2000l);

			req.setBuyerId((int)placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_017() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 开团失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 砍价团id
			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);

			// 参团
			TradingServiceResp placeOrder2 = BargainGroupService
					.joinGroup(bizId);

			long orderId = placeOrder2.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, -1);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(2000l);

			req.setBuyerId((int)placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_018() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 开团初始状态");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 砍价团id
			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);

			// 参团
			TradingServiceResp placeOrder2 = BargainGroupService
					.joinGroup(bizId);

			long orderId = placeOrder2.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, 0);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(2000l);

			req.setBuyerId((int)placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_019() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 开团成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 砍价团id
			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);

			// 参团
			TradingServiceResp placeOrder2 = BargainGroupService
					.joinGroup(bizId);

			long orderId = placeOrder2.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, 1);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(2000l);

			req.setBuyerId((int)placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_020() {
		Logger.start(true, "验证砍价团信息，查询成功, 开团(团长) 组团成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 砍价团id
			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);

			// 参团
			TradingServiceResp placeOrder2 = BargainGroupService
					.joinGroup(bizId);

			long orderId = placeOrder2.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 1, 1);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(2000l);

			req.setBuyerId((int)placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_021() {
		Logger.start(true, "验证砍价团信息，查询成功, 参团(团员) 参团失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 砍价团id
			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);

			// 参团
			TradingServiceResp placeOrder2 = BargainGroupService
					.joinGroup(bizId);

			long orderId = placeOrder2.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 2, -2);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(2000l);

			req.setBuyerId((int)placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_022() {
		Logger.start(true, "验证砍价团信息，查询成功, 参团(团员) 参团成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 砍价团id
			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);

			// 参团
			TradingServiceResp placeOrder2 = BargainGroupService
					.joinGroup(bizId);

			long orderId = placeOrder2.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			BargainGroupService.notifyOrderBizStatus(bizId, orderId, 2, 2);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(2000l);

			req.setBuyerId((int)placeOrderResp.getUserId());
			req.setOrderNum(1);
			req.setLastOrderId(0);
			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderInfosV2_023() {

		Logger.start(true, "传入订单列表，查询成功");

		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			List<Integer> orderStatusList = new ArrayList<Integer>();

			orderStatusList.add(OrderStatusEnum.OrderEstablish.getValue());

			req.setBuyerId(userId);
			req.setOrderNum(10);
			req.setOrderStatusList(orderStatusList);

			req.setOrderIdList(Arrays.asList(2368338699L, 2368348699L, 2371838699L,
					2368328699L, 2368318699L));

			call.setData(req);
			call.callService();
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}